package knapsack;

import static org.junit.Assert.*;
import org.junit.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class Knapsack01Test {
	private List<Pack> products;
	Pack p1 = new Pack(1, 5);
	Pack p2 = new Pack(4, 2);
	Pack p3 = new Pack(3, 1);
	Pack p4 = new Pack(2, 6);
	
	@Before
	public void setUp(){
		products = new ArrayList<Pack>();
		products.add(p1);
		products.add(p2);
		products.add(p3);
		products.add(p4);
	}
	
	@Test
	public void testFillKnapsackPD() {
		List<Pack> result = Knapsack01.fillKnapsackPD(products, 10);
		assertTrue(result.containsAll(products));
		
		result = Knapsack01.fillKnapsackPD(products, 7);
		assertTrue(result.contains(p1));
		assertTrue(result.contains(p2));
		assertTrue(result.contains(p4));
		assertFalse(result.contains(p3));
		
		result = Knapsack01.fillKnapsackPD(products, 0);
		assertTrue(result.isEmpty());
	}
	
	@Test
	public void testFillKnapsackRec() {
		List<Pack> result = Knapsack01.fillKnapsackRec(products, 10);
		
		assertTrue(result.containsAll(products));
		
		result = Knapsack01.fillKnapsackRec(products, 7);
		assertTrue(result.contains(p1));
		assertTrue(result.contains(p2));
		assertTrue(result.contains(p4));
		assertFalse(result.contains(p3));
	
		result = Knapsack01.fillKnapsackRec(products, 0);
		assertTrue(result.isEmpty());
	}

}
